<template>
	<el-drawer title="产品制程" v-model="visible" destroy-on-close>
		<el-container>
			<el-header>
				<div class="left-panel">
					<el-button icon="el-icon-plus" type="primary" @click="open_dialog" />
				</div>
			</el-header>
			<el-main class="nopadding">
				<scTable ref="table" :api-obj="apiObj" :params="reqParams" row-key="id" hideDo hideContextMenu>
					<el-table-column label="#" type="index" width="40"></el-table-column>
					<el-table-column property="product.itemCode" label="产品编号" align="center" width="100" />
					<el-table-column property="product.itemName" label="产品名称" align="center" width="220" />
					<el-table-column align="center" fixed="right" label="操作">
						<template #default="scope">
							<el-popconfirm title="确定删除吗？" @confirm="table_del(scope.row, scope.$index)">
								<template #reference>
									<el-button text type="primary" size="small">删除</el-button>
								</template>
							</el-popconfirm>
						</template>
					</el-table-column>
				</scTable>
			</el-main>
			<modify ref="modify" @complete="complete" />
		</el-container>
	</el-drawer>
</template>

<script>
import modify from "./productSelectorModify";

export default {
	components: {
		modify,
	},
	data() {
		return {
			apiObj: this.$API.procroutingproduct.pagesbyroutingid,
			visible: false,
			parentItem: {},
			reqParams: {
				routingId: 0,
			},
		};
	},
	methods: {
		complete() {
			this.$refs.table.refresh();
		},
		async open(item) {
			this.parentItem = item;
			this.reqParams.routingId = this.parentItem.id;
			this.visible = true;
		},
		async table_del(row) {
			let resp = await this.$API.procroutingproduct.delete.delete([row.id]);
			if (resp.code == 200) {
				this.$refs.table.refresh();
				this.$message.success("删除成功");
			} else {
				this.$alert(resp.message, "提示", { type: "error" });
			}
		},
		open_dialog() {
			this.$refs.modify.open(this.parentItem);
		},
	},
};
</script>
